//没有服务器数据库，写死用户邮箱
var user_email = "965747597@qq.com";
//写死的邮箱对应密码
var user_password = "ppnn13%dkstFeb.1st";
//写死的手机号(随便写的手机号)
var user_phone = "15110113224";
//用户登陆的方式
var flag = 1;

//切换用户登陆界面
function email_login(){
	if(flag == 0){
		document.getElementById("useremail").style.display = "block";
		document.getElementById("userphone").style.display = "none";
		document.getElementById("password").style.display = "block";
		document.getElementById("v_code").style.display = "none";
		document.getElementById("EmailAndPassword").style.display = "block";
		document.getElementById("PhoneAndVerificationCode").style.display = "none";
	}
	flag = 1;
}
function phone_login(){
	if(flag == 1){
		document.getElementById("useremail").style.display = "none";
		document.getElementById("userphone").style.display = "block";
		document.getElementById("password").style.display = "none";
		document.getElementById("v_code").style.display = "block";
		document.getElementById("EmailAndPassword").style.display = "none";
		document.getElementById("PhoneAndVerificationCode").style.display = "block";
	}
	flag = 0;
}

//手机验证码
var v_Code = "325684";
function v_code(){
	var userPhone = document.getElementById("userphone").value;
	if(userPhone != ""){
		alert("由此信息代替为手机接收验证短信！\n请输入以下数字(验证码)"+v_Code);
	}else{
		alert("请输入手机号以接收验证码!");
	}
}

//登陆逻辑
function checkLogin(){
	//邮箱登陆
	if(flag == 1){
		var userEmail = document.getElementById("useremail").value;
		var passWord = document.getElementById("password").value;
		if(user_email == userEmail){
			if(user_password == passWord){
				//记住账户密码
				var check_boxs = document.getElementById('remember').checked;
				if(check_boxs){
					localStorage.setItem('username',userEmail);
					localStorage.setItem('password',passWord);
					//记录上次登陆方式
					localStorage.setItem('loginmethod','email');
				}
				localStorage.setItem('checkboxstatus',check_boxs);
				alert("登录成功！");
			}else{
				alert("密码错误！\n/*请查看网页源码以获得该账号的密码！*/");
			}
		}else{
			if(user_email == ""){
				alert("请输入邮箱！");
			}else{
				alert("该邮箱不存在或格式错误！\n/*请查看网页源码以获得测试账号和密码！*/");
			}
		}
	}else{//手机登陆
		var userPhone = document.getElementById("userphone").value;
		var vCode = document.getElementById("verificationCode").value;
		if(user_phone == userPhone){
			if(v_Code == vCode){
				//记住手机号
				var check_boxs = document.getElementById('remember').checked;
				console.log(check_boxs+'1');
				if(check_boxs){
					localStorage.setItem('userphone',userPhone);
					//记录上次登陆方式
					localStorage.setItem('loginmethod','phone');
				}
				localStorage.setItem('checkboxstatus',check_boxs);
				console.log(check_boxs+'2');
				alert("登录成功！");
			}else{
				alert("验证码错误，请重试或重新获取！");
			}
		}else{
			if(userPhone == ""){
				alert("请输入手机号！\n/*请查看网页源代码以获得手机号*/");
			}else{
				alert("手机号不存在！\n/*请查看网页源代码以获得手机号*/");
			}	
		}
	}
}
//加载用户信息（如果有！）
 window.onload=function(){
 	var checkBoxStatus = localStorage.getItem('checkboxstatus');
 	if(checkBoxStatus == 'true') {
 		//加载上次登陆保存的数据
		var user_name = localStorage.getItem('username');
		var pass_word = localStorage.getItem('password');
		var user_phone = localStorage.getItem('userphone');
		var login_ = localStorage.getItem('loginmethod');
		//检验用户名和密码是否为空，以及上次登陆的方式
		if(user_name != '' && pass_word != '' && login_ == 'email') {
			document.getElementById('useremail').value = user_email;
			document.getElementById('password').value = pass_word;
		}
		if(user_phone != '' && login_ == 'phone') {
			document.getElementById('userphone').value = user_phone;
		}
		document.getElementById('remember').checked = localStorage.getItem('checkboxstatus');
	}else{
		//清空记录
		localStorage.setItem('username', "");
		localStorage.setItem('password', "");
		localStorage.setItem('userphone',"");
	}
 }
 	
